from rest_framework import serializers
from course.models import CourseCategory,Teacher,Course,CourseChapter,CourseLesson



class CourseCategoryModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseCategory
        fields = ["id","name"]


class CourseTeacherModelSerializer(serializers.ModelSerializer):
    """课程所属老师的序列化器"""
    class Meta:
        model = Teacher
        fields = ["id","name","role","title","signature","brief","image"]

class CourseModelSerializer(serializers.ModelSerializer):
    """课程信息的序列化器"""
    teacher = CourseTeacherModelSerializer() # 老师 1 : 多课程
    # teacher = CourseTeacherModelSerializer(many=True) # 多对1
    class Meta:
        model = Course
        # print(123)
        fields = ("id","name","course_img","students","lessons","pub_lessons","price","teacher","lesson_list")


# 专题课程
class CourseRetrieveSerializer(serializers.ModelSerializer):
    teacher = CourseTeacherModelSerializer()

    class Meta:
        model = Course
        fields = ["id", "name", "course_img", "students", "lessons", "pub_lessons", "price", "teacher", "brief",
                     "level_name"]

# 课程课时
class CourseLessonSerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseLesson
        fields = ["id","name","duration","free_trail"]


# 课程章节
class CourseChapterSerializer(serializers.ModelSerializer):
    coursesections = CourseLessonSerializer(many=True)
    class Meta:
        model = CourseChapter
        fields = ["chapter","name","summary","coursesections"]


